package top.humbleyuan.linkedlist;

import top.humbleyuan.datastructure.linkedlist.LinkNode;

import java.util.HashSet;
import java.util.Set;

/**
 * @Author HumbleYuan
 * @Date 2020/5/18 22:46
 * @Des 链表组件
 */
public class LeetCode_817 {
    public static void main(String[] args) {
        /**
         * 数据准备
         */
        LinkNode head = new LinkNode(6);
        int[] vals = {2,3,5,7};
        head = LinkNode.formLink(head,vals);

        int[] G = {2,5,7,9};

        Set<Integer> nums = new HashSet<>();
        int i = 0;
        while (i < G.length) {
            nums.add(G[i++]);
        }

        int count = 0;
        LinkNode temp = head;
        boolean inCom = false;
        while (temp != null) {
            if(nums.contains(temp.val) && !inCom) {
                inCom = true;
                count ++;
            }else if(!nums.contains(temp.val)){
                inCom = false;
            }
            temp = temp.next;
        }
        System.out.println(count);
    }
}
